Skip to content

DOC: update the pandas.Series.dt.dayofweek docstring #20230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed

DOC: update the pandas.Series.dt.dayofweek docstring #20230

wants to merge 4 commits into from

Conversation

koaning
Copy link

@koaning koaning commented Mar 10, 2018

Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):

  • PR title is "DOC: update the docstring"
  • The validation script passes: scripts/validate_docstrings.py <your-function-or-method>
  • The PEP8 style check passes: git diff upstream/master -u -- "*.py" | flake8 --diff
  • The html version looks good: python doc/make.py --single <your-function-or-method>
  • It has been proofread on language by another sprint participant

Please include the output of the validation script below between the "```" ticks:

################################################################################
#################### Docstring (pandas.Series.dt.dayofweek) ####################
################################################################################

The day of the week with Monday=0, Sunday=6.

Return the day of the week. It is assumed the week starts on
Monday, which is denoted by 0 and ends on Sunday which is denoted
by 6.

See Also
--------
pandas.Series.dt.dayofweek : Identical method.
pandas.Series.dt.weekday : Identical method.

Returns
-------
ndarray of integers indicating the day of the week

Examples
--------
>>> dates = pd.date_range("2016-12-31", "2017-01-08", freq="D")
>>> s = pd.Series(dates)
>>> day_name = s.dt.strftime("%A")
>>> pd.DataFrame({'dt': s, 'num': s.dt.weekday, 'day': day_name})
          dt  num        day
0 2016-12-31    5   Saturday
1 2017-01-01    6     Sunday
2 2017-01-02    0     Monday
3 2017-01-03    1    Tuesday
4 2017-01-04    2  Wednesday
5 2017-01-05    3   Thursday
6 2017-01-06    4     Friday
7 2017-01-07    5   Saturday
8 2017-01-08    6     Sunday

Note that `series.dt.dayofweek` and `series.dt.weekday` are the same.

>>> s.dt.dayofweek
0    5
1    6
2    0
3    1
4    2
5    3
6    4
7    5
8    6
dtype: int64
>>> s.dt.weekday
0    5
1    6
2    0
3    1
4    2
5    3
6    4
7    5
8    6
dtype: int64

################################################################################
################################## Validation ##################################
################################################################################

Docstring for "pandas.Series.dt.dayofweek" correct. :)


Returns
-------
ndarray of integers indicating the day of the week
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of Series.dt it actually returns a Series of integers


See Also
--------
pandas.Series.dt.dayofweek : Identical method.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can say alias

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add day_name as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it into this now.

    See Also
    --------
    pandas.Series.dt.dayofweek : alias
    pandas.Series.dt.weekday : alias
    pandas.Series.dt.day_name : 
        Return the day names of the DateTimeIndex with specified locale.

Note that the docstring for dayofweek and weekday is the exact same.

    dayofweek = _field_accessor('dayofweek', 'dow', _dayofweek_doc)
    weekday = dayofweek

Series
Containing integers indicating the week number.

ndarray of integers indicating the day of the week
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate line

--------
>>> dates = pd.date_range("2016-12-31", "2017-01-08", freq="D")
>>> s = pd.Series(dates)
>>> day_name = s.dt.strftime("%A")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have a method day_name for this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did not know this. i was confused because i saw weekday_name but this was depricated. i've changed the code and added day_name to the "see also" too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the code here as well and simply use day_name

7 2017-01-07 5 Saturday
8 2017-01-08 6 Sunday

Note: `pandas.Series.dt.dayofweek`/`pandas.Series.dt.weekday` are the same.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are operating on an Index here (and the doc-string goes for both)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jreback could you elaborate? im not sure what you mean with that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore my comment here


Returns
-------
ndarray
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these return an Index

--------
>>> dates = pd.date_range("2016-12-31", "2017-01-08", freq="D")
>>> s = pd.Series(dates)
>>> day_name = s.dt.strftime("%A")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the code here as well and simply use day_name

7 2017-01-07 5 Saturday
8 2017-01-08 6 Sunday

Note: `pandas.Series.dt.dayofweek`/`pandas.Series.dt.weekday` are the same.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore my comment here

7 5
8 6
dtype: int64
>>> s.dt.weekday
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to show both, just use dayofweek

@datapythonista
Copy link
Member

Closing in favor of #21823 (the original fork/branch don't exist and can't fix the conflict in this PR).

Thanks @koaning for the contribution, and sorry for the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants